//Biến toàn cục
var content_width = $(window).width();
var content_height = $(window).height() - $(".header").height();
var $hash = window.location.hash;
var $strHash = $hash.split("/");
var $typeContent = $strHash[1];
var $typeActive = $strHash[2];

//Khởi tạo jQuery
$(function(){
    //Loading Main
    $(".loading").stop().animate({
        top: "+="+(content_height/2 + 77),
    }, 4000, "easeOutElastic", function() {
        $(".main").stop().animate({
            opacity: 1,
        }, 500, function() {
            $(".curtainLeft").stop().animate({
                left: "-="+(content_width/2),
            }, 2000, "easeInOutQuart", function() {});
            
            $(".curtainRight").stop().animate({
                right: "-="+(content_width/2),
            }, 2000, "easeInOutQuart", function() {
                $(".obj-loading").stop().animate({
                    opacity: 0,
                }, 1000, function() {
                    $(".obj-loading").hide();
                });
            });  
        });
    });
    
    //Choice Type Default
    if ($typeContent == undefined || $typeContent != "place"){
        choice_type("contest");
    }else{
        choice_type("place");
    }
    
    //Set Maps Size
    $(".wraper").width(content_width);
    $(".wraper").height(content_height);
    
    //Set Width Marquee
    var marquee_width = ($(window).width() - ($(".h-logo").width() + $(".h-nav").width() + $(".h-profile").width() + 80));
    $("marquee").width(marquee_width);
    
    $(window).resize(function(){
        var marquee_width = ($(window).width() - ($(".h-logo").width() + $(".h-nav").width() + $(".h-profile").width() + 80));
        $("marquee").width(marquee_width);
    });
    
    //Process Header Navigation Click
    $(".h-nav .item").click(function(){
        choice_type($(this).data("type"));
    });
    
    //Show Menu Profile
    $(".hp-show").live('click',function(){
        $(".hp-hide").toggle();
    });
});

//Choice Type Show
function choice_type(type){
    $(".h-nav .item").each(function(index){ $(this).removeClass("active"); });
    $(".h-nav .item[data-type='"+type+"']").addClass("active");
    $("#fancybox-close").trigger("click");
    switch(type){
        case "contest":
            $(".ajax-processing").fadeIn(100);
            clearTimeout(0);
            setTimeout(function(){
                $.ajax({
                    url : Path_Url + "contest",
                    success: function(data){
                        $(".content").html(data);
                        $(".ajax-processing").fadeOut(100);
                    }
                });
            },3000)
            break;
        case "place":
            $(".ajax-processing").fadeIn(100);
            clearTimeout(0);
            setTimeout(function(){
                $.ajax({
                    url : Path_Url + "place",
                    success: function(data){
                        $(".content").html(data);
                        $(".ajax-processing").fadeOut(100);
                    }
                });
            },3000);
            break; 
    }
}

